/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.app.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yanlight.app.dal.dao.AlipayConfigDAO;
import com.yanlight.app.dal.entity.AlipayConfig;
import com.yanlight.app.response.AlipayPidResponse;
import com.yanlight.app.service.AlipayService;
import com.yanlight.exception.ErrorType;
import com.yanlight.exception.TradeException;

/**
 * 
 * @author haolw
 * @time 2017/08/25
 */
@Service
public class AlipayServiceImpl implements AlipayService {
	private static final String ALIPAY_CONFIG_KEY = "trade_alipay_config_";
	@Autowired
	private AlipayConfigDAO alipayConfigDAO;

	@Override
	public AlipayPidResponse findPid(Integer companyId) {
		AlipayPidResponse response = new AlipayPidResponse();
		AlipayConfig alipayConfig = alipayConfigDAO.findByCompanyId(companyId);
		if (alipayConfig == null) {
			throw TradeException.error(ErrorType.NOT_EXIST_RECORD);
		}
		response.setPid(alipayConfig.getMchUserId());
		return response;
	}

	private String getAlipayConfigKey(Integer companyId) {
		return ALIPAY_CONFIG_KEY + companyId;
	}

}
